package cn.sxgan.gen.enums;

import cn.sxgan.gen.utils.StrUtils;

public enum DataSourceType {
    MySQL("MySQL", "com.mysql.cj.jdbc.Driver"),
    Oracle("Oracle", "oracle.jdbc.driver.OracleDriver"),
    PostgreSQL("PostgreSQL", "org.postgresql.Driver"),
    SQLServer("SQLServer", "com.microsoft.sqlserver.jdbc.SQLServerDriver"),
    DM("DM", "dm.jdbc.driver.DmDriver"),
    Clickhouse("Clickhouse", "com.clickhouse.jdbc.ClickHouseDriver"),
    KingBase("KingBase", "com.kingbase8.Driver");
    
    private String typeName;
    private final String driverClass;
    
    DataSourceType(String typeName, String driverClass) {
        this.typeName = typeName;
        this.driverClass = driverClass;
    }
    
    public String getTypeName() {
        return typeName;
    }
    
    public String getDriverClass() {
        return driverClass;
    }
    
    
    public static DataSourceType getEnumValue(String type) {
        for (DataSourceType value : DataSourceType.values()) {
            if (StrUtils.equalsAny(type, value.typeName)) {
                return value;
            }
        }
        if (StrUtils.equalsAny(type, "SQLServer", "Microsoft SQL Server")) {
            return SQLServer;
        }
        return null;
    }
    
    public static String getTypeName(String type) {
        for (DataSourceType value : DataSourceType.values()) {
            if (StrUtils.equalsAny(type, value.typeName)) {
                return value.typeName;
            }
        }
        return null;
    }
}